import { failed } from '../../../lib/utils';
import { http_build_query } from 'locutus/php/url';
import { md5 } from 'locutus/php/strings';
export class QianyingPayment {
    constructor(
        public shopId,
        public key,
        public returnUrl,
        public callbackUrl
    )   {

    }


    buildPayUrl(
        bankType,
        orderId,
        money,
        failedUrl
    ){
        let build_q = function(ps){
            let buf = [];
            for(const [key,val] of Object.entries(ps)){
                buf.push(`${key}=${val}`);
            }
            return buf.join("&");
        }
        let url = 'http://www.qianyingnet.com/pay/';
        let params = {
            uid : this.shopId,
            type : bankType,
            m : money,
            orderid : orderId,
            callbackurl : this.callbackUrl,
            sign : '',
            gofalse : failedUrl,
            gotrue : this.returnUrl,
            // key : this.key,
            // posturl : url,
            charset : 'utf-8',
            token : '',
        }
        let {
            uid,
            type,
            m,
            orderid,
            callbackurl
        } = params;
        console.log(params,this)
        params.sign = md5(build_q({uid,type,m,orderid,callbackurl}) + this.key).toUpperCase();
        return url + '?' + build_q(params);
    }
}